package tarena.netctoss.view;

import java.util.List;

import tarena.netctoss.dao.Pagination;
import tarena.netctoss.dao.RightCondition;
import tarena.netctoss.po.Module;
import tarena.netctoss.po.Operation;
import tarena.netctoss.po.Right;
import tarena.netctoss.service.ModuleService;
import tarena.netctoss.service.OperationService;
import tarena.netctoss.service.RightService;

import com.opensymphony.xwork2.ActionSupport;

/**
 * 权限管理控制层
 * 
 * @author Wangpeihu
 * @team [Never give up]
 * @since JDK1.6(建议)
 * @date 2010-3-10
 */
public class RightAction extends ActionSupport {
	private static final long serialVersionUID = 1L;
	private RightService rightService;
	private ModuleService moduleService;
	private OperationService operationService;
	private Right right;
	private Pagination page;
	private RightCondition rc;
	private List<Right> rightList;
	private List<Module> moduleList;

	/** 操作名称 */
	private List<Operation> operationList;
	private Operation operation;

	public void setRightService(RightService rightService) {
		this.rightService = rightService;
	}

	public Right getRight() {
		return right;
	}

	public void setRight(Right right) {
		this.right = right;
	}

	public Pagination getPage() {
		return page;
	}

	public void setPage(Pagination page) {
		this.page = page;
	}

	public RightCondition getRc() {
		return rc;
	}

	public void setRc(RightCondition rc) {
		this.rc = rc;
	}

	/********************************/

	/**
	 * 权限首页
	 * 
	 * @return
	 */
	public String index() {
		return SUCCESS;
	}

	/**
	 * 权限浏览
	 * 
	 * @return
	 */
	public String rightBrowse() {
		// 分页条件
		if (null == page) {
			page = new Pagination();
			page.setPage(1);
			page.setPageSize(10);
		}
		// 查询条件
		if (null == rc) {
			rc = new RightCondition();
		}
		rightList = rightService.findAll(rc, page);
		return SUCCESS;
	}

	/**
	 * 权限增加表单请求
	 * 
	 * @return
	 */
	public String rightAddForm() {
		moduleList = moduleService.findAll();
		operationList = operationService.findAll();
		return SUCCESS;
	}

	/**
	 * 权限资费增加
	 * 
	 * @return
	 */
	public String rightAdd() {
		if (null != right) {
			rightService.save(right);
		}
		return SUCCESS;
	}

	/**
	 * 权限修改列表请求
	 * 
	 * @return
	 */
	public String rightPrepareUpdate() {
		// 分页条件
		if (null == page) {
			page = new Pagination();
			page.setPage(1);
			page.setPageSize(10);
		}
		// 查询条件
		if (null == rc) {
			rc = new RightCondition();
		}
		rightList = rightService.findAll(rc, page);
		return SUCCESS;
	}

	/**
	 * 权限修表单请求
	 * 
	 * @return
	 */
	public String rightUpdateForm() {
		if (null != right) {
			right = rightService.findById(right.getId());
		}
		operationList = operationService.findAll();
		moduleList = moduleService.findAll();
		return SUCCESS;
	}

	/**
	 * 权限资费修改
	 * 
	 * @return
	 */
	public String rightUpdate() {
		if (null != right) {
			rightService.update(right);
		}
		return SUCCESS;
	}

	/**
	 * 权限删除列表单请求
	 * 
	 * @return
	 */
	public String rightDeleteForm() {
		return SUCCESS;
	}

	/**
	 * 确认权限删除
	 * 
	 * @return
	 */
	public String rightDelete() {
		return SUCCESS;
	}

	public List<Right> getRightList() {
		return rightList;
	}

	public void setRightList(List<Right> rightList) {
		this.rightList = rightList;
	}

	public Operation getOperation() {
		return operation;
	}

	public void setOperation(Operation operation) {
		this.operation = operation;
	}

	public List<Module> getModuleList() {
		return moduleList;
	}

	public void setModuleList(List<Module> moduleList) {
		this.moduleList = moduleList;
	}

	public void setModuleService(ModuleService moduleService) {
		this.moduleService = moduleService;
	}

	public List<Operation> getOperationList() {
		return operationList;
	}

	public void setOperationList(List<Operation> operationList) {
		this.operationList = operationList;
	}

	public void setOperationService(OperationService operationService) {
		this.operationService = operationService;
	}

}
